package system;
import java.sql.*;
public class Test{
	String test_id,opeater_id,test_name;
	
	public void setTest_id(String str){
		try{
			byte b[]=str.getBytes("ISO-8859-1");
            test_id=new String(b);
		} catch(Exception e){}
	}
	public String getTest_id(){
		return test_id;
	}
	
	public void setOpeater_id(String str){
		try{
			byte b[]=str.getBytes("ISO-8859-1");
            opeater_id=new String(b);
		} catch(Exception e){}
	}
	public String getOpeater_id(){
		return opeater_id;
	}
	
	public void setTest_name(String str){
		test_name=str;
		//try{
			//byte b[]=str.getBytes("ISO-8859-1");
            //test_name=new String(b);
		//} catch(Exception e){}
	}
	public String getTest_name(){
		return test_name;
	}
	
	public boolean getCreate(){
		boolean  insert=false;
		String insertCondition="insert into testing values('"+test_id+"','"+opeater_id+"','"+test_name+"','0','0')";
		Connection con;
	    Statement sql;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
    try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		int m=sql.executeUpdate(insertCondition);
		if(m!=0){
			insert=true;			
		}
		con.close();
	}
	catch(SQLException e1){insert=false;}
	return insert;
	}
	
	public int countPlus(String testid){
		int count=0;
		String[] testInf={"1","2","3","4","5"};
		String queryCondition="select * from testing where test_id='"+testid+"'";
		String updateCondition;
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
    try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery(queryCondition);
		if(rs.next()){
			for(int i=0;i<5;i++){
				testInf[i]=rs.getString(i+1);
				}			
		}
		count=Integer.parseInt(testInf[4])+1;
		updateCondition="update testing set count="+count+" where test_id='"+testid+"'";
		int m=sql.executeUpdate(updateCondition);
		con.close();
	}
	catch(SQLException e1){count=0;}
	return count;
	}
	
	public String[] getTestInf(String testid){
		String[] testInf={"1","2","3","4","5"};
		Connection con;
	    Statement sql;
	    ResultSet rs;
	    try{
	    	Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	    	}
	    catch(Exception e){}
   
        try{
		String uri = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test_system";
		String user = "sa";
		String password = "sa";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		rs=sql.executeQuery("SELECT * from testing where test_id='"+testid+"'");
		if(rs.next()){
			for(int i=0;i<5;i++){
				testInf[i]=rs.getString(i+1);
				}			
		}
		con.close();
	    } catch(SQLException e1){}
	    return testInf;
	}
}